<?php

Class Controller_Administrar Extends Controller_Base {


	
	
	
	function showAllJobs(){

		
			$job=new Jobs();
			$c=new Criteria();
			$c->Add(JobsPeer::VISIBLE,'S');
			$jobsList = JobsPeer::doSelect($c);
			

			
		try {
		
			$this->template->set('jobs', $jobsList);
			$this->template->show ('jobs');
				
		}catch (TemplateException $e){
			$this->template->remove('error_code');
			$this->template->set('error_code', $e->getMessage());
			$this->template->show('error');
		}
	}
	
	
	function showActiveJobs(){

		
			$job=new Jobs();
			$c=new Criteria();
			$c->Add(JobsPeer::VISIBLE,'S');
			$c->Add(JobsPeer::ACTIVE,'S');
			$jobsList = JobsPeer::doSelect($c);
			

			
		try {
		
			$this->template->set('jobs', $jobsList);
			$this->template->show ('jobs');
				
		}catch (TemplateException $e){
			$this->template->remove('error_code');
			$this->template->set('error_code', $e->getMessage());
			$this->template->show('error');
		}
	}
	
	
	
	function editJob(){
			
			
			$job=JobsPeer::retrieveByPK($_GET['id']);
			if (!$job){
				$job = new Jobs();
			
			}
			
			try {
		
			$this->template->set('job', $job);
			$this->template->show ('job');
				
		}catch (TemplateException $e){
			$this->template->remove('error_code');
			$this->template->set('error_code', $e->getMessage());
			$this->template->show('error');
		}

			
	}
	
	
	
	
	
	function save(){
			
			
			$u=JobsPeer::retrieveByPK($_POST['id']);
			if (!$u){
				$u = new Jobs();
				$u->setCreateData(mktime());
				$u->setLastRunData(null);
				
			}
			$u->setTitle($_POST['title']);
			$u->setDescription($_POST['description']);
			$u->setCode($_POST['code']);
			$u->save();
			
			$this->showAllJobs();
			
	}
	
	
	function ShowJob(){
				
				$u=JobsPeer::retrieveByPK($_GET['id']);
				$u->setVisible('S');
				$u->save();
	}
	
	function HideJob(){
				
				$u=JobsPeer::retrieveByPK($_GET['id']);
				$u->setVisible('N');
				$u->setActive('N');
				$u->save();
	}
	
	
	function ActiveJob(){
				$u=JobsPeer::retrieveByPK($_GET['id']);
				$u->setActive('S');
				$u->setLastRunData(mktime());
				$u->save();
	}
	
	
	function UnactiveJob(){
				
				$u->setActive('N');
				$u->save();
	}
	
	
}
?>